package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/2 10:46
 * @apiNote
 */

public class Test00263IsUgly {

    public boolean isUgly(int n) {
        if(n <= 0){
            return false;
        }
        int[] factors = {5,3,2};
        for(int factor : factors){
            while(n % factor == 0){
                n /= factor;
            }
        }
        return n == 1;
    }

    public boolean isUgly1(int n) {
        if (n == 0) {
            return false;
        }
        while (true) {
            if (n == 1) {
                return true;
            }
            if (n % 2 == 0) {
                n /= 2;
            } else if(n % 3 == 0) {
                n /= 3;
            } else if(n % 5 == 0) {
                n /= 5;
            } else {
                return false;
            }
        }
    }
}
